#ifndef dq_Singleton_h
#define dq_Singleton_h

namespace serika
{
	namespace dq
	{
		template <class Type>
		class Singleton
		{
			Singleton() : mType(0) {}
			~Singleton() {}

		public:
			static Type* Instance()
			{
				Type*& type = Singleton<Type>::Me()->mType;
				if (!type)
				{
					type = new Type;
					//type->Initialize();
				}
				return type;
			}

			static void Close()
			{
				Type*& type = Singleton<Type>::Me()->mType;
				if (type)
				{
					//type->Finalize();
					delete type;
					type = 0;
				}
			}

		private:
			static Singleton<Type>* Me()
			{
				static Singleton<Type>* instance = 0;
				if (!instance)
				{
					instance = new Singleton<Type>;
				}
				return instance;
			}

		private:
			Type* mType;
		};
	}
}

#endif
